package main

// 创建一个用于统计字节和字符 (rune) 的程序，并对字符串 asSASA ddd dsjkdsjs dk 进行分析，
// 然后再分析 asSASA ddd dsjkdsjsこん dk，最后解释两者不同的原因（提示：使用 unicode/utf8 包）。
import (
	"unicode/utf8"
)

func countByte(s string) (c int) {
	b := []byte(s)
	c = len(b)
	return
}

func countRune(s string) (c int) {
	r := []rune(s)
	c = len(r)
	return
}

func main() {
	s1 := "asSASA ddd dsjkdsjs dk"
	s2 := "asSASA ddd dsjkdsjsこん dk"
	print("count s1 in byte is: ", countByte(s1), "\n") // 22
	print("count s2 in byte is: ", countByte(s2), "\n") // 28 uft8编码战占用3个字节, こん两个字符则占用3个了字节
	print("count s1 in rune is: ", countRune(s1), "\n") // 22
	print("count s2 in rune is: ", countRune(s2), "\n") // 24 按字符计算相比s1多了两个字符
	// utf8编码
	print("count s1 length in rune use utf8: ", utf8.RuneCountInString(s1), "\n")
	print("count s2 length in rune use utf8: ", utf8.RuneCountInString(s2), "\n")
}
